<?php
/* @var $this DefaultController */
/* @var $model FormModel */
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
Util::tsRegisterAssetJs('_formulario.js');
Yii::app()->clientScript->registerCssFile($this->module->assetsUrl . '/css/nosey-form-formulario.css');
?>


<div class="modal-header">

    <h4><i class="icon-file-text"></i>  <?php echo $model->name ?></h4>
</div>



<!--<p>< ?php echo $model->description ?></p>-->

<?php
$form = $this->beginWidget('ext.AweCrud.components.AweActiveForm', array(
    'id' => 'submit-form',
    'enableAjaxValidation' => true,
    'action' => Yii::app()->createUrl('/nosey/default/modalFormulario/id/' . $model->id . '/entity_id/' . $entity_id),
    'clientOptions' => array('validateOnSubmit' => true, 'validateOnChange' => false,),
    'enableClientValidation' => false,
        ));
?>
<div class="row-fluid">
    <div class="modal-body">
        <p class="note"><?php echo Yii::t('noseyModule.app', 'Fields with') ?> <span class="required">*</span> <?php echo Yii::t('noseyModule.app', 'are required') ?>.</p>

        <?php // echo $form->errorSummary($form_model)  ?>
        <?php echo $form->hiddenField($model, 'id') ?>

        <?php $cont = 0; ?>
        <?php foreach ($model->sections as $section): ?>
            <div class="nsy_form_section"> 
                <div class="nsy_form_section_header ">
                    <h4><?php echo $section->name ?></h4>

                </div>

                <div class="nsy_form_section_content">
                    <?php foreach ($section->fields as $field): ?>
                        <div class=" nsy_form_row ">

                            <?php
                            switch ($field->field_type) {

                                case Field::FIELD_TYPE_TEXT:
                                    if ($field->widget_type == Field::WIDGET_TYPE_TEXT) {
                                        echo $form->textFieldRow($form_model, $field->id, array('class' => ' nsy_element_input', 'tabindex' => "$cont"));
                                    } elseif ($field->widget_type == Field::WIDGET_TYPE_TEXTAREA) {
                                        echo $form->textAreaRow($form_model, $field->id, array('class' => 'nsy_element_input', 'tabindex' => "$cont"));
                                    }
                                    break;
                                case Field::FIELD_TYPE_SIMPLE:
                                    if ($field->widget_type == Field::WIDGET_TYPE_RADIO) {
                                        echo $form->radioButtonListRow($form_model, $field->id, CHtml::listData($field->options, 'id', 'label'), array('class' => 'nsy_element_check', 'tabindex' => "$cont"));
                                    } elseif ($field->widget_type == Field::WIDGET_TYPE_SELECT) {
                                        echo $form->dropDownListRow($form_model, $field->id, CHtml::listData($field->options, 'id', 'label'), array('empty' => Yii::t('noseyModule.app', '- Select one -'), 'class' => 'nsy_element_select', 'tabindex' => "$cont"));
                                    }
                                    break;
                                case Field::FIELD_TYPE_MULTIPLE:
                                    if ($field->widget_type == Field::WIDGET_TYPE_CHECKBOX) {
                                        echo $form->checkBoxListRow($form_model, $field->id, CHtml::listData($field->options, 'id', 'label'), array('multiple' => true, 'class' => 'nsy_element_check', 'tabindex' => "$cont"));
                                    } elseif ($field->widget_type == Field::WIDGET_TYPE_SELECT) {
                                        echo $form->dropDownListRow($form_model, $field->id, CHtml::listData($field->options, 'id', 'label'), array('multiple' => true, 'class' => 'nsy_element_select', 'tabindex' => "$cont"));
                                    }
                                    break;
                                case Field::FIELD_TYPE_BOOLEAN:
//                                echo '<div class="control-group">';
                                    echo $form->labelEx($form_model, $field->id);
                                    $this->widget(
                                            'bootstrap.widgets.TbToggleButton', array(
                                        'model' => $form_model,
                                        'disabledLabel' => 'NO',
                                        'enabledLabel' => 'SI',
                                        'width' => 100,
                                        'attribute' => "$field->id",
                                        'htmlOptions' => array('tabindex' => "$cont"),
                                        'onChange' => 'js:function($el, status, e){}'
                                            )
                                    );
                                    echo '<span class="help-inline error" id="DynamicFormModel_' . $field->id . '_em_" style=""></span>';
//                                echo '</div>';
//                                        echo $form->checkBoxRow($form_model, $field->id, array('class' => 'nsy_element_boolean'));
                                    break;
                                case Field::FIELD_TYPE_DATE:
                                    echo $form->datepickerRow($form_model, $field->id, array('options' => array('autoclose' => true), 'class' => 'nsy_element_date', 'tabindex' => "$cont"));
                                    break;
                                case Field::WIDGET_TYPE_STAR_RATING:
                                    if ($field->widget_type == Field::WIDGET_TYPE_STAR_RATING) {
                                        echo '<div class="control-group">';
                                        echo $form->labelEx($form_model, $field->id);
                                        $this->widget('CStarRating', array(
                                            'name' => "DynamicFormModel[$field->id]",
                                            'value' => '0',
                                            'allowEmpty' => false,
                                            'minRating' => 1,
                                            'maxRating' => $field->options[0]->label,
                                            'starCount' => $field->options[0]->label,
                                            'htmlOptions' => array('tabindex' => "$cont"),
                                        ));

                                        echo '<span class="help-inline error" id="DynamicFormModel_' . $field->id . '_em_" style=""></span>';
                                        echo '</div>';
                                    } elseif ($field->widget_type == Field::WIDGET_TYPE_SELECT) {
                                        $valoresData = array();
                                        for ($i = 1; $i <= $field->options[0]->label; $i++) {
                                            $valoresData[$i] = $i;
                                        }
                                        echo $form->select2Row($form_model, $field->id, array(
                                            'asDropDownList' => true,
                                            'empty' => 0,
//                                        'empty' => '- Ninguna -',
//                                                   'empty' =>array(0=> '- Ninguna -'),
                                            'data' => $valoresData,
                                            'tabindex' => "$cont",
//                                        'class' => 'span6',
                                        ));
                                    }

                                    break;
                                default: break;
                            }
                            $cont++;
                            ?>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        <?php endforeach; ?>

    </div>
    <div class="modal-footer">
        <!--<div class="nsy_buttons control-group center">-->

        <div class="center">
            <!--<div class="form-actions-float">-->
            <?php
            $this->widget('bootstrap.widgets.TbButton', array(
//            'buttonType' => 'submit',
                'type' => 'success',
                'label' => Yii::t('noseyModule.app', 'Save'),
                'htmlOptions' => array(
                    'onClick' => 'js: AjaxAtualizacionInformacion("#submit-form")')
            ));
            ?>
        </div>
        <!--</div>-->


        <!--</div>-->
    </div>
    <?php $this->endWidget(); ?>


</div>